package com.lcn.consumer.lcnconsumer.service.impl;

import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.lcn.consumer.lcnconsumer.bean.Depart;
import com.lcn.consumer.lcnconsumer.feign.DepartFeign;
import com.lcn.consumer.lcnconsumer.repository.DepartRepository;
import com.lcn.consumer.lcnconsumer.service.DepartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
public class DepartServiceImpl implements DepartService {

    @Autowired
    private DepartRepository repository;

    @Autowired
    private DepartFeign departFeign;

    // 插入
    @Override
    @Transactional
    @LcnTransaction
    public boolean saveDepart(Depart depart) {

        // 本地插入
        Depart obj1 = repository.save(depart);


        Depart d2 = new Depart();
        d2.setName(depart.getName()+"feign");

        //通过feign组件远程调用了另一个服务，实现保存
        boolean obj2 = departFeign.saveDepart(d2);

//        int a = 1/0;

        return true;
    }


}
